#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>

#define MAX_SIZE             1024
#define OPENFILE             "1"
#define PACKAGE_PATH         "/media/usb"

int main(int argc, char *argv[])
{
    int n;
    int fd[2];
    pid_t pid;
    char line[MAX_SIZE];
	int fd_test;

    if (pipe(fd) < 0)
        perror("pipe error");
    if ((pid = fork()) < 0) {
        perror("fork error");
    } else if (pid > 0) {
        close(fd[0]); 
		close(STDOUT_FILENO);
		dup2(fd[1], STDOUT_FILENO);
/*
		sprintf(cmd, "mount %s %s -t iso9660 -o loop",
				"ota_update.iso", PACKAGE_PATH);
		system(cmd);
*/
		system("tar -zxvf tmp/system.tar.gz");


    } else {
        close(fd[1]);
		fd_test = open(OPENFILE, O_RDWR | O_CREAT, 0777);
		while((n = read(fd[0], line, MAX_SIZE)) > 0)
			if(write(fd_test, line, n) != n)
				perror("write error");
    }
	close(fd_test);

    return 0;
}
